import {reactive} from "vue";
import {useStore, mapMutations} from "vuex";

export function useMutations(moduleName: string, mapper: string[]): Object {
  const store = useStore()
  //  获取到对应对象的functions
  const storeMutationFns = mapMutations(moduleName, mapper)
  //对数据进行转换
  const storeMutations = reactive({})
  Object.keys(storeMutationFns).forEach(fnKey => {
    // @ts-ignore
    storeMutations[fnKey] = storeMutationFns[fnKey].bind({$store: store})
  })
  return storeMutations
}
